package chapter;

public class object_interface1 {
    public static void main(String[] args) {
    Computer computer = new Computer();
    Light light = new Light();
    Light light2 = new Light();
    computer.usb1 = light;
    computer.usb2 = light2;
        computer.powerSupply();
     new Bird1().fly();
     new Fly(){
         public void fly() {
             System.out.println("使用飞行器飞翔");
         }
     }.fly();
    }
}

interface Fly{
    public void fly();
}

class Bird1 implements Fly{
    public void fly() {
        System.out.println("用翅膀飞翔");
    }
}
//属性必须是静态的，行为必须是抽象的
//接口可以继承其他接口
//类的对象必须遵循接口，称之为实现（implements）
interface USBInterface {
//TODO java默认了abstract属性
}
interface USBSupply extends USBInterface {
    public void powerSupply();
}
interface USBReceive extends USBInterface {
    public void powerReceive();
}
class Computer implements USBSupply {
    public USBReceive usb1;
    public USBReceive usb2;

    public void powerSupply() {
        System.out.println("电脑提供能源");
        usb1.powerReceive();
        usb2.powerReceive();//相当于电脑接口
    }
}
class Light implements USBReceive{
      public void powerReceive() {
          System.out.println("电灯接受能源");
      }
}